#include <stdio.h>
#include <stdlib.h>

struct msg_st
{
    long int msg_type;
    char text[BUFSIZ];
};

typedef struct clientInfo
{
    char *clientID;
    char *clientPass;
    char *clientAddr;
} ClientInfo;

typedef struct MsgA
{
    char *K_CT;
} MsgA;

// 加密后的消息B
typedef struct MsgB
{
    char *clientID;
    char *clientAddr;
    char *vaildity;
    char *K_CT;
} MsgB;

typedef struct MsgC
{
    char *serviceID;
    MsgB msgB;
} MsgC;

typedef struct MsgD
{
    char *clientID;
    char *timestamp;    
} MsgD;

typedef struct MsgE
{
    char *serviceID;
    // ST
    char *clientID;
    char *clientAddr;
    char *vaildity;
    char *K_CS;
} MsgE;

typedef struct MsgF
{
    char *K_CS; 
} MsgF;

typedef struct MsgG
{
    char *clientID;
    char *timestamp;    
} MsgG;

typedef struct MsgH
{
    char *clientID;
    char *ts;    
} MsgH;

void MsgAInit(MsgA *msgA)
{
    msgA->K_CT = (char *)malloc(BUFSIZ * sizeof(char));
}

void MsgBInit(MsgB *msgB)
{
    msgB->clientID = (char *)malloc(BUFSIZ * sizeof(char));
    msgB->clientAddr = (char *)malloc(BUFSIZ * sizeof(char));
    msgB->vaildity = (char *)malloc(BUFSIZ * sizeof(char));
    msgB->K_CT = (char *)malloc(BUFSIZ * sizeof(char));
}

void MsgCInit(MsgC *msgC)
{
    msgC->serviceID = (char *)malloc(BUFSIZ * sizeof(char));
    MsgBInit(&(msgC->msgB));
}

void MsgDInit(MsgD *msgD)
{
    msgD->clientID = (char *)malloc(BUFSIZ * sizeof(char));
    msgD->timestamp = (char *)malloc(BUFSIZ * sizeof(char));    
}

void MsgEInit(MsgE *msgE)
{
    msgE->serviceID = (char *)malloc(BUFSIZ * sizeof(char));
    msgE->clientID = (char *)malloc(BUFSIZ * sizeof(char));
    msgE->clientAddr = (char *)malloc(BUFSIZ * sizeof(char));
    msgE->vaildity = (char *)malloc(BUFSIZ * sizeof(char));
    msgE->K_CS = (char *)malloc(BUFSIZ * sizeof(char));
}

void MsgFInit(MsgF *msgF)
{
    msgF->K_CS = (char *)malloc(BUFSIZ * sizeof(char));
}

void MsgGInit(MsgG *msgG)
{
    msgG->clientID = (char *)malloc(BUFSIZ * sizeof(char));
    msgG->timestamp = (char *)malloc(BUFSIZ * sizeof(char));    
}

void MsgHInit(MsgH *msgH)
{
    msgH->clientID = (char *)malloc(BUFSIZ * sizeof(char));
    msgH->ts = (char *)malloc(BUFSIZ * sizeof(char));    
}

char *MD5Encryption(unsigned char *input)
{
    char *output;
    output = (char *)malloc(16*sizeof(char));
    unsigned int inputLen = strlen(input);
    MD5_CTX md5;
    MD5Init(&md5);
    MD5Update(&md5, input, inputLen);
    MD5Final(&md5, output);
    return output;
}


